package api

import (
	"getaway/basic/config"
	ai "getaway/basic/proto/aiproto"
	"getaway/handler/request"
	"getaway/handler/response"
	"github.com/gin-gonic/gin"
)

// ChatWithAI
// @Summary      多轮对话
// @Description  多轮对话
// @Tags         AI模块
// @Accept       json
// @Produce      json
// @Param        base   body    request.ChatWithAIReq    true  "参数"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.Response
// @Failure      500  {object}  response.Response
// @Router       /ai/chatWithAI [post]
// @Security TokenAuth
func ChatWithAI(c *gin.Context) {
	var req request.ChatWithAIReq
	if err := c.ShouldBind(&req); err != nil {
		response.SrvError(c, "参数格式错误", err.Error())
		return
	}
	resp, err := config.AiClient.ChatWithAI(c, &ai.ChatWithAIReq{
		UserId:    req.UserID,
		SessionId: req.SessionID,
		Message:   req.Message,
	})
	if err != nil {
		response.SrvError(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", resp)
}

// GetHistory
// @Summary      获取对话记录
// @Description  获取对话记录
// @Tags         AI模块
// @Accept       json
// @Produce      json
// @Param        base   body    request.GetHistoryReq    true  "参数"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.Response
// @Failure      500  {object}  response.Response
// @Router       /ai/getHistory [post]
// @Security TokenAuth
func GetHistory(c *gin.Context) {
	var req request.GetHistoryReq
	if err := c.ShouldBind(&req); err != nil {
		response.SrvError(c, err.Error(), nil)
		return
	}
	resp, err := config.AiClient.GetHistory(c, &ai.GetHistoryReq{
		UserId:    req.UserID,
		SessionId: req.SessionID,
		Limit:     req.Limit,
	})
	if err != nil {
		response.SrvError(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", resp)
}

// GetSessionList
// @Summary      获取会话列表
// @Description  获取会话列表
// @Tags         AI模块
// @Accept       json
// @Produce      json
// @Param        base   body    request.GetSessionListReq    true  "参数"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.Response
// @Failure      500  {object}  response.Response
// @Router       /ai/getSessionList [post]
// @Security TokenAuth
func GetSessionList(c *gin.Context) {
	var req request.GetSessionListReq
	if err := c.ShouldBind(&req); err != nil {
		response.SrvError(c, err.Error(), nil)
		return
	}
	resp, err := config.AiClient.GetSessionList(c, &ai.GetSessionListReq{
		UserId: req.UserID,
		Limit:  req.Limit,
	})
	if err != nil {
		response.SrvError(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", resp)
}
